
package com.yjh.admin.controller.user;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yjh.admin.config.data.DataSource;
import com.yjh.admin.entity.user.SysUserRole;
import com.yjh.admin.server.sys.SysUserRoleService;
import util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;



/**
 * 用户角色表
 *
 * @author GuoBin
 * @date 2020-07-10 10:57:08
 */
@ApiOperation("用户角色表")
@RestController
@AllArgsConstructor
@RequestMapping("/sysuserrole")
public class SysUserRoleController {

  private final SysUserRoleService sysUserRoleService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param sysUserRole 用户角色表
   * @return
   */
  @ApiOperation("分页查询")
  @PostMapping("/page")
  @DataSource("sys_db")
  public R getSysUserRolePage(@RequestBody Page page, SysUserRole sysUserRole) {
    return  new R<>(sysUserRoleService.page(page,Wrappers.query(sysUserRole)));
  }


  /**
   * id查询用户角色表
   * @param userId id
   * @return R
   */
  @ApiOperation("通过id查询用户角色表")
  @GetMapping("/getById")
  @DataSource("sys_db")
  public R getById(@RequestParam("userId") Integer userId){
    return new R<>(sysUserRoleService.getById(userId));
  }

  /**
   * 新增用户角色表
   * @param sysUserRole 用户角色表
   * @return R
   */
  @ApiOperation("新增用户角色表")
  @PostMapping
  @DataSource("sys_db")
  public R save(@RequestBody SysUserRole sysUserRole){
    return new R<>(sysUserRoleService.save(sysUserRole));
  }

  /**
   * 修改用户角色表
   * @param sysUserRole 用户角色表
   * @return R
   */
  @ApiOperation("修改用户角色表")
  @PutMapping
  @DataSource("sys_db")
  public R updateById(@RequestBody SysUserRole sysUserRole){
    return new R<>(sysUserRoleService.updateById(sysUserRole));
  }

  /**
   * 通过id删除用户角色表
   * @param userId id
   * @return R
   */
  @ApiOperation("删除用户角色表")
  @DeleteMapping("/removeById")
  @DataSource("sys_db")
  public R removeById(@RequestParam("userId") Integer userId){
    return new R<>(sysUserRoleService.removeById(userId));
  }

  /**
   * 查询全部
   * @param
   * @return R
   */
  @ApiOperation("查询全部")
  @GetMapping("/queryAll")
  @DataSource("sys_db")
  public R queryAll(){
    return new R<>(sysUserRoleService.list());
  }

}
